#include <DateTime.h>
#include <sstream>
#include <string>
#include <iostream>
using namespace std;



DateTime::DateTime(int timestamp)
{
	stringstream ss;
    time_t timeTemp;
    ss << timestamp;
    ss >> timeTemp;
    tm* timeStuct = gmtime(&timeTemp);       //
    this->year = timeStuct->tm_year + 1900;
    this->month = timeStuct->tm_mon + 1;
    this->day = timeStuct->tm_mday;
    this->hour = timeStuct->tm_hour;
    this->minute = timeStuct->tm_min;
    this->second = timeStuct->tm_sec;
    this->timestamp = timestamp;
}


DateTime::DateTime()
{
    time_t now = time(0);
    *this = DateTime((int)now);
}


//
string DateTime::toString()
{
    ostringstream oss;
    oss << this->year << "-";
    oss << this->month << "-";
    oss << this->day << " ";
    oss << this->hour << ":";
    oss << this->minute << ":";
    oss << this->second;
    return oss.str();
}

//
int DateTime::toTimestamp()
{
    return this->timestamp;
}
